﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace YXShop.Web.admin.accessories
{
    public partial class question_list : System.Web.UI.Page
    {
        YXShop.BLL.Accessories.Question questionBll = new YXShop.BLL.Accessories.Question();
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack){
                YXShop.Common.PromptInfo.Popedom("012002001");
                if (ChangeHope.WebPage.PageRequest.GetFormString("Option") != string.Empty && ChangeHope.WebPage.PageRequest.GetFormString("id") != "")
                {
                    if (YXShop.Common.PromptInfo.Message("012002003") != "ok")
                    {
                        string types = Request["Option"].Trim();
                        string id = ChangeHope.WebPage.PageRequest.GetFormString("id");
                        if (types == "del")
                        {
                            questionBll.Delete(Convert.ToInt32(id));
                        }
                        if (types == "delAll")
                        {
                            questionBll.DeleteAll(id);
                        }
                    }
                    else
                    {
                        Response.Write("no");
                    }
                    Response.End();

                    return;
                }
                this.LitQuestion.Text = GetList();
            }
        }

        public string GetList()
        {
            string questID = Request["QuestID"].ToString();
            ChangeHope.WebPage.Table table = new ChangeHope.WebPage.Table();
            ChangeHope.DataBase.DataByPage datapage = questionBll.GetList(Convert.ToInt32(questID));
            table.AddHeadCol("","选择");
            table.AddHeadCol("","问题");
            table.AddHeadCol("","问题类型");
            table.AddHeadCol("","常规操作");
            table.AddRow();
            if(datapage.DataReader!=null){
                while(datapage.DataReader.Read()){
                    table.AddCol("<input id=\"cbTm\"  type=\"checkbox\" value=" + datapage.DataReader["id"] + " />");
                    table.AddCol(datapage.DataReader["questionContent"].ToString());
                    table.AddCol(QuestionType(datapage.DataReader["questionType"].ToString()));
                    table.AddCol("<a href='question_edit.aspx?Action=edit&QuestID=" + datapage.DataReader["questionId"].ToString() + "&ID=" + datapage.DataReader["id"] + "'>修改</a>  <a href='#' onclick='Del(" + datapage.DataReader["id"] + ")' >删除</a>  <a href='question_log.aspx?QuestType=" + datapage.DataReader["questionType"].ToString() + "&ID=" + datapage.DataReader["id"] + "'>投票记录查看</a>");
                    table.AddRow();
                }
            }
            string view = table.GetTable() + datapage.PageToolBar;
            datapage.Dispose();
            datapage = null;
            return view;
        }


        #region 问题类型
        protected string QuestionType(string TypeID)
        {
            string Str = "";
            switch (TypeID)
            {
                case "1":
                    Str = "单行文本";
                    break;
                case "2":
                    Str = "多行文本";
                    break;
                case "3":
                    Str = "单选";
                    break;
                case "4":
                    Str = "多选";
                    break;
                case "5":
                    Str = "下拉";
                    break;
                case "6":
                    Str = "是/否(单选框)";
                    break;
            }
            return Str;
        }
        #endregion

        protected void btnSelect_Click(object sender, EventArgs e)
        {
            this.LitQuestion.Text = GetList();
        }
    }
}
